<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            text-align: center;
            margin: 0px auto;
        }
        .box{
            width: 320px;
            height: 320px;
            border: 1px solid black;
        }
        .ss{
            width: 18px;
            height: 18px;
            border: 1px solid black;
            float: left;
        }
        .bg{
            background-color: red;
        }
        .bg-active{
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div class="box" id="box">
    
    </div>
</body>
<script>
    var init=function(){
        var box=document.getElementById("box");
            for(var i=1;i<=256;i++){
                var div=document.createElement("div");
                div.className="ss bg"
                div.onmouseover=function(){
                    this.className="ss bg-active";
                }
                div.onmouseout=function(){
                    this.className="ss bg";
                }
                var a=function(k){
                    div.onclick = function()
                    {

                        alert(k);
                    }
                }
                a(i);
                box.appendChild(div);
        }
        if(true){
            console.log(i);
        }
    }
    init();
</script>
</html>